/**
 * 员工修改js
 */
var comValidform=null;
var returnStatus=false;
var employeeUpdate={
	dataCache:null,
	
	bindChangeDept:function(val){
		var url = 'common/ComDutiesCtrl/getDutiesList';
		var params={
				'deptId':val
		}
		var cb = function(data){
			if(data.resultCode==200){
				$('.com-addForm select[name="dutiesId"]').empty();
				var option='<option value="">请选择</option>';
				for(var i=0;i<data.result.length;i++){
					var singleObj=data.result[i];
					option=option+'<option value="'+singleObj.id+'">'+singleObj.name+'</option>';
				}
				$('.com-addForm select[name="dutiesId"]').append(option);
			}
		};
		sendApiNoLoadSync(url, params, cb, 'POST');
	},
	
	startEvent:function(){
		//获取部门
		var url = 'common/ComDepartmentCtrl/getDepartmentList';
		var cb = function(data){
			if(data.resultCode==200){
				var option='<option value="">请选择</option>';
				for(var i=0;i<data.result.length;i++){
					var singleObj=data.result[i];
					option=option+'<option value="'+singleObj.id+'">'+singleObj.name+'</option>';
				}
				$('.com-addForm select[name="deptId"]').append(option);
				$('.com-addForm select[name="deptId"]').on('click',function(){
					employeeUpdate.bindChangeDept($(this).val());
				});
			}
		};
		sendApiNoLoadSync(url, {}, cb, 'POST');
		
		employeeUpdate.showInfoById();
		
		comValidform=$(".com-addForm").Validform({
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				var url = 'mgr/SysUserCtrl/updateSysUser';
				var params = jsUtils.serializeJson($('.com-addForm'));
				delete params.roleList;
				
				var cb = function(data){
					alert(data.msg);
					//成功返回
					if(data.resultCode==200){
						//关闭窗口并刷新数据
						art.dialog.close();
						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},
	
	showInfoById:function(){
		var updId=art.dialog.data('updId');  //修改id
		var url = 'mgr/SysUserCtrl/getSysUserById';
		var params ={
				'id':updId
		};
		var cb = function(data){
			if(data.resultCode==200){
				var ret=data.result;
				for(var i in ret){
					var text=ret[i];
					if(i=='deptId'){
						$('#com-addForm select[name="'+i+'"]').val(text);
						employeeUpdate.bindChangeDept(text);
						continue;
					}else if(i=='dutiesId'){
						$('#com-addForm select[name="'+i+'"]').val(text);
						continue;
					}else if(i=='entryTime'||i=='birthday'||i=='leaveTime'){
						text=text==null?'':(new Date(text)).format('yyyy-MM-dd');
					}
					$('#com-addForm input[name="'+i+'"]').val(text);
				}
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},
	
	init:function(){
		employeeUpdate.startEvent();
	}
}
$(document).ready(function() {
	employeeUpdate.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}